//
//  PPNetCenter.h
//  PPNetworking
//
//  Created by 邓标祥 on 2020/12/15.
//

#import <Foundation/Foundation.h>
#import "PPNetConst.h"
#import "PPNetRequest.h"
@class PPNetConfig;
NS_ASSUME_NONNULL_BEGIN

@interface PPNetCenter : NSObject

/** 单例 */
+ (instancetype)defaultCenter;

/** 通用服务器地址 */
@property (nonatomic, copy, nullable, readonly) NSString *generalServer;

/** 通用请求参数 */
@property (nonatomic, strong, nullable, readonly) NSMutableDictionary<NSString *, id> *generalParameters;

/** 通用请求头 */
@property (nonatomic, strong, nullable, readonly) NSMutableDictionary<NSString *, NSString *> *generalHeaders;

/** 是否打开打印台日志*/
@property (nonatomic, assign) BOOL consoleLog;


/// 全局网络通用配置
/// @param block block
+ (void)setupConfig:(void(^)(PPNetConfig *config))block;


/// 添加通用header
/// @param value value
/// @param field key
- (void)setGeneralHeaderValue:(nullable NSString *)value forField:(NSString *)field;


/// 添加通用参数
/// @param value value
/// @param key key
- (void)setGeneralParameterValue:(nullable id)value forKey:(NSString *)key;


/// 发送单个http请求
/// @param request request
/// @param successBlock 网络层成功block
/// @param failureBlock 网络层失败block
+ (nullable NSString *)sendRequest:(PPNetRequest *)request
                         onSuccess:(nullable PPNetSuccessBlock)successBlock
                         onFailure:(nullable PPNetFailureBlock)failureBlock;


/// 发送批量http请求
/// @param configBlock 用于配置各个请求对象
/// @param finishedBlock 所有请求结束后的统一回调
+ (nullable NSString *)sendBatchRequest:(PPNetBatchRequestConfigBlock)configBlock
                             onFinished:(PPBCFinishedBlock)finishedBlock;


/// 取消请求（单请求或批量请求）
/// @param identifier 唯一标识
+ (void)cancelRequest:(NSString *)identifier;



/// 取消全部正在请求中的任务
+ (void)cancelAllRequest;
@end


/// ************************************ 全省港澳所有既分割线唯独呢条至靓仔 ************************************ ///

@interface PPNetConfig : NSObject

@property (nonatomic, copy, nullable) NSString *generalServer;


@property (nonatomic, strong, nullable) NSDictionary<NSString *, id> *generalParameters;


@property (nonatomic, strong, nullable) NSDictionary<NSString *, NSString *> *generalHeaders;


@property (nonatomic, assign) BOOL consoleLog;

@end

NS_ASSUME_NONNULL_END
